
//
// 110310 - AH - Created.
//

package org.soekrat.gui.swing.chat.convention;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JCheckBox;

import org.soekrat.engine.motor.Motor;
import org.soekrat.engine.sparewheel.SpareWheel;

/**
 * <p>
 *   Control that toggles if
 *   {@link Motor} should consult 
 *   {@link SpareWheel} or not.
 * </p>
 * @author Arne Halvorsen (AH)
 * @author Laetitia Le Chatton (LLC)
 */
@SuppressWarnings("serial")
public final class ToggleSpareWheelControl extends JCheckBox 
{
  private final Motor m_motor;
  
  /**
   * <p>
   *   Constructor.
   * </p>
   * @param motor {@link Motor}.
   */
  public ToggleSpareWheelControl(Motor motor)
  {
    super("Consult SpareWheel");
    
    if (motor==null)
    {
      throw new NullPointerException("motor");
    }
    
    m_motor=motor;
    
    setSelected(motor.getUseSpareWheel());
    
    addActionListener
    (
      new ActionListener() 
      {      
        public void actionPerformed(ActionEvent e) 
        {
          boolean v=isSelected();  
          m_motor.setUseSpareWheel(v);
        }
      }
    );
  }
  
}
